package com.woniu.controller;

import com.woniu.been.entity.TLogin;
import com.woniu.been.entity.TMenu;
import com.woniu.been.entity.vo.TLoginVo;
import com.woniu.been.entity.vo.TMenuVo;
import com.woniu.service.TMenuService;
import com.woniu.utils.PageResult;
import com.woniu.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/api/TMenuController")
@CrossOrigin
public class TMenuController {
    @Autowired
    private TMenuService tMenuService;

    /*
    * 根据老师姓名查询老师的菜单
    * */
    @GetMapping("findMenus")
    public ResponseResult findMenus(@RequestParam String teacherName) {
        List<TMenu> list = tMenuService.findMenus(teacherName);
        return ResponseResult.success(list);
    }

    /*
    * 分页 动态查询所有菜单
    * */
    @PostMapping("findAllMenus")
    public ResponseResult<PageResult> findAllMenus(@RequestBody TMenuVo tMenuVo) {
        System.out.println("分页 动态查询所有菜单  tMenuVo"+tMenuVo);
        PageResult result = tMenuService.findAllMenus(tMenuVo,tMenuVo.getPageNum(), tMenuVo.getPageSize());
        System.out.println("分页 动态查询所有菜单 result"+result);
        return ResponseResult.success(result);
    }

    /*
    * 添加菜单
    * */
    @PostMapping("insertMenu")
    public ResponseResult<TMenu> insertMenu(@RequestBody TMenu tMenu){
        tMenuService.insertMenu(tMenu);
        return ResponseResult.success();
    }

    /*
    * 根据id修改菜单名称
    * */
    @PutMapping("editMenu")
    public ResponseResult<TMenu> editMenu(@RequestBody TMenu tMenu){
        tMenuService.editMenu(tMenu);
        return ResponseResult.success();
    }

    /*
    * 根据菜单id删除菜单
    * */
    @DeleteMapping("deleteMenu")
    public ResponseResult<TMenu> deleteMenu(@RequestParam Integer id){
        tMenuService.deleteMenu(id);
        return ResponseResult.success();
    }
}
